/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class SearchResultsMapSearchIndex
    {
    
        private String indexNameField;

        private Decimal? resultsField;

        private Decimal? pagesField;

        private  CorrectedQuery correctedQueryField;
        private Decimal? relevanceRankField;

        private List<String> ASINField;


        /// <summary>
        /// Gets and sets the IndexName property.
        /// </summary>
        [XmlElementAttribute(ElementName = "IndexName")]
        public String IndexName
        {
            get { return this.indexNameField ; }
            set { this.indexNameField= value; }
        }



        /// <summary>
        /// Sets the IndexName property
        /// </summary>
        /// <param name="indexName">IndexName property</param>
        /// <returns>this instance</returns>
        public SearchResultsMapSearchIndex WithIndexName(String indexName)
        {
            this.indexNameField = indexName;
            return this;
        }



        /// <summary>
        /// Checks if IndexName property is set
        /// </summary>
        /// <returns>true if IndexName property is set</returns>
        public Boolean IsSetIndexName()
        {
            return  this.indexNameField != null;

        }


        /// <summary>
        /// Gets and sets the Results property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Results")]
        public Decimal Results
        {
            get { return this.resultsField.GetValueOrDefault() ; }
            set { this.resultsField= value; }
        }



        /// <summary>
        /// Sets the Results property
        /// </summary>
        /// <param name="results">Results property</param>
        /// <returns>this instance</returns>
        public SearchResultsMapSearchIndex WithResults(Decimal results)
        {
            this.resultsField = results;
            return this;
        }



        /// <summary>
        /// Checks if Results property is set
        /// </summary>
        /// <returns>true if Results property is set</returns>
        public Boolean IsSetResults()
        {
            return  this.resultsField != null;

        }


        /// <summary>
        /// Gets and sets the Pages property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Pages")]
        public Decimal Pages
        {
            get { return this.pagesField.GetValueOrDefault() ; }
            set { this.pagesField= value; }
        }



        /// <summary>
        /// Sets the Pages property
        /// </summary>
        /// <param name="pages">Pages property</param>
        /// <returns>this instance</returns>
        public SearchResultsMapSearchIndex WithPages(Decimal pages)
        {
            this.pagesField = pages;
            return this;
        }



        /// <summary>
        /// Checks if Pages property is set
        /// </summary>
        /// <returns>true if Pages property is set</returns>
        public Boolean IsSetPages()
        {
            return  this.pagesField != null;

        }


        /// <summary>
        /// Gets and sets the CorrectedQuery property.
        /// </summary>
        [XmlElementAttribute(ElementName = "CorrectedQuery")]
        public CorrectedQuery CorrectedQuery
        {
            get { return this.correctedQueryField ; }
            set { this.correctedQueryField = value; }
        }



        /// <summary>
        /// Sets the CorrectedQuery property
        /// </summary>
        /// <param name="correctedQuery">CorrectedQuery property</param>
        /// <returns>this instance</returns>
        public SearchResultsMapSearchIndex WithCorrectedQuery(CorrectedQuery correctedQuery)
        {
            this.correctedQueryField = correctedQuery;
            return this;
        }



        /// <summary>
        /// Checks if CorrectedQuery property is set
        /// </summary>
        /// <returns>true if CorrectedQuery property is set</returns>
        public Boolean IsSetCorrectedQuery()
        {
            return this.correctedQueryField != null;
        }




        /// <summary>
        /// Gets and sets the RelevanceRank property.
        /// </summary>
        [XmlElementAttribute(ElementName = "RelevanceRank")]
        public Decimal RelevanceRank
        {
            get { return this.relevanceRankField.GetValueOrDefault() ; }
            set { this.relevanceRankField= value; }
        }



        /// <summary>
        /// Sets the RelevanceRank property
        /// </summary>
        /// <param name="relevanceRank">RelevanceRank property</param>
        /// <returns>this instance</returns>
        public SearchResultsMapSearchIndex WithRelevanceRank(Decimal relevanceRank)
        {
            this.relevanceRankField = relevanceRank;
            return this;
        }



        /// <summary>
        /// Checks if RelevanceRank property is set
        /// </summary>
        /// <returns>true if RelevanceRank property is set</returns>
        public Boolean IsSetRelevanceRank()
        {
            return  this.relevanceRankField != null;

        }


        /// <summary>
        /// Gets and sets the ASIN property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ASIN")]
        public List<String> ASIN
        {
            get
            {
                if (this.ASINField == null)
                {
                    this.ASINField = new List<String>();
                }
                return this.ASINField;
            }
            set { this.ASINField =  value; }
        }



        /// <summary>
        /// Sets the ASIN property
        /// </summary>
        /// <param name="list">ASIN property</param>
        /// <returns>this instance</returns>
        public SearchResultsMapSearchIndex WithASIN(params String[] list)
        {
            foreach (String item in list)
            {
                ASIN.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks of ASIN property is set
        /// </summary>
        /// <returns>true if ASIN property is set</returns>
        public Boolean IsSetASIN()
        {
            return (ASIN.Count > 0);
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetIndexName()) {
                xml.Append("<IndexName>");
                xml.Append(EscapeXML(this.IndexName));
                xml.Append("</IndexName>");
            }
            if (IsSetResults()) {
                xml.Append("<Results>");
                xml.Append(this.Results);
                xml.Append("</Results>");
            }
            if (IsSetPages()) {
                xml.Append("<Pages>");
                xml.Append(this.Pages);
                xml.Append("</Pages>");
            }
            if (IsSetCorrectedQuery()) {
                CorrectedQuery  correctedQuery = this.CorrectedQuery;
                xml.Append("<CorrectedQuery>");
                xml.Append(correctedQuery.ToXMLFragment());
                xml.Append("</CorrectedQuery>");
            } 
            if (IsSetRelevanceRank()) {
                xml.Append("<RelevanceRank>");
                xml.Append(this.RelevanceRank);
                xml.Append("</RelevanceRank>");
            }
            List<String> ASINList  =  this.ASIN;
            foreach (String ASIN in ASINList) { 
                xml.Append("<ASIN>");
                xml.Append(EscapeXML(ASIN));
                xml.Append("</ASIN>");
            }	
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}